package com.bojin.studio.ubattery;

import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Picture;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class tabBlog extends Activity {
    /** Called when the activity is first created. */	
	WebView wv;
	   @Override
	   public void onCreate(Bundle savedInstanceState) {
	       super.onCreate(savedInstanceState);
	       setContentView(R.layout.blog);
	       wv = (WebView)findViewById(R.id.webView1);
	       wv.getSettings().setJavaScriptEnabled(true);
	       wv.setWebViewClient(new WebViewClient()
	       {
	         @Override
	         public void onPageFinished(WebView view, String url)
	         {
	           // TODO Auto-generated method stub
	          
	           Picture picture = view.capturePicture();
	           ByteArrayOutputStream baos = new ByteArrayOutputStream();
	          
	           int width = picture.getWidth();
	           int height = picture.getHeight();

	           if (width > 0 && height > 0)
	           {

	             Bitmap bitmap = Bitmap.createBitmap(width, height,
	                 Bitmap.Config.ARGB_8888);

	             Canvas canvas = new Canvas(bitmap);

	             picture.draw(canvas);

	             bitmap.compress(Bitmap.CompressFormat.JPEG, 90, baos);

	             FileOutputStream fos = null;
	             try
	             {
	               fos = new FileOutputStream("/sdcard/BS_Battery_"
	                   + System.currentTimeMillis() + ".jpg");
	               if (fos != null)
	               {
	                 bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
	                 fos.close();
	               }

	             } catch (Exception e)
	             {
	               e.printStackTrace();
	             }

	            // Toast.makeText(view.getContext(), "Snapshot OK", Toast.LENGTH_SHORT).show();

	           }
	           super.onPageFinished(view, url);
	         }
	       });
	       wv.loadUrl("http://bsbattery.blogspot.com/");	       
	   }
}

